package com.veritech.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import com.veritech.model.Service;
import com.veritech.service.ServiceService;

public class IndexController implements Controller{
	@Autowired
	private ServiceService serviceService;
	
	protected final Log logger = LogFactory.getLog(getClass());
	
	public void setServiceService(ServiceService ss){
		serviceService = ss;
	}
	
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mv = new ModelAndView("index.jsp");
		logger.info("CONTEXT PATH: " + request.getRequestURL().toString());
		List<Service> services = serviceService.getAllService();
		mv.addObject("services", services);
		logger.info("Create index controller");
		return mv;
	}
}
